﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Logic;
using Entities;

namespace Presentation
{
	public partial class GeneralSettings : UserControl
	{
		public GeneralSettings()
		{
			InitializeComponent();
		}

		public void SetProperties()
		{
			//
		}

		public void Initialize()
		{
			GenreBL gbl = new GenreBL();
			List<Genre> genres = gbl.List();

			comboBoxGenres.Items.AddRange(gbl.List().ToArray());
		}

		private void buttonAdd_Click(object sender, EventArgs e)
		{
			if (comboBoxGenres.Text.Trim() != "" && !comboBoxGenres.Items.Contains(comboBoxGenres.Text.Trim()))
			{
				Genre g = new Genre();
				g.Name = comboBoxGenres.Text.Trim();

				GenreBL gbl = new GenreBL();
				if (gbl.Save(g))
				{
					g = gbl.GetLastAdded();

					comboBoxGenres.Items.Add(g);
					comboBoxGenres.Text = "";
				}
			}
		}

		private void buttonRemove_Click(object sender, EventArgs e)
		{
			if (comboBoxGenres.SelectedItem != null)
			{
				GenreBL gbl = new GenreBL();

				if (gbl.Delete((Genre)(comboBoxGenres.SelectedItem)))
					comboBoxGenres.Items.RemoveAt(comboBoxGenres.SelectedIndex);
			}
		}
	}
}
